<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height:40px;width:100%"
  >
    <!-- 左侧 -->
    <el-col>
      <span>{{ treeNode.name }}</span>
    </el-col>
    <!-- 右侧 -->
    <el-col :span="4">
      <el-row type="flex" justify="space-around">
        <!-- 负责人 -->
        <el-col>{{ treeNode.manager }}</el-col>
        <!-- 下拉菜单 -->
        <el-col>
          <el-dropdown @command="operatDepts">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <slot>
                <el-dropdown-item command="add">添加子部门</el-dropdown-item>
                <el-dropdown-item
                  v-if="!isRoot"
                  command="edit"
                >编辑部门</el-dropdown-item>
                <el-dropdown-item
                  v-if="!isRoot"
                  command="del"
                >删除部门</el-dropdown-item>
              </slot>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
// import { delDepartments } from '@/api/departments'
export default {
  name: 'TreeTools',
  components: {},
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {}
  },
  computed: {},
  created() {},
  methods: {
    operatDepts(command) {
      if (command === 'add') {
        // 新增
        this.$emit('addDept', this.treeNode)
      } else if (command === 'edit') {
        // 编辑
        this.$emit('editDept', this.treeNode)
      } else if (command === 'del') {
        // // 删除
        // this.$confirm('确认删除该部门吗', '提示', {
        //   confirmButtonText: '确认',
        //   cancelButtonText: '取消',
        //   type: 'success'
        // })
        //   .then(async action => {
        //     await delDepartments(this.treeNode.id)
        //     this.$message({
        //       message: '删除成功',
        //       type: 'success',
        //       showClose: true,
        //       duration: 3000
        //     })
        //     this.$emit('delDepts')
        //   })
        //   .catch(() => {})
      }
    }
  }
}
</script>

<style scoped></style>
